import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  { path: "/", redirect: "/index/user" },
  // 路由的重定向 当是/打开在用户管理页面

  {
    path: "/index",
    name: "index",
    component: () => import("../views/Index.vue"),
    children: [
      {
        path: "good",
        name: "good",
        component: () => import("../views/Good.vue"),
      },
      {
        path: "user",
        name: "user",
        component: () => import("../views/User.vue"),
      },
      {
        path: "limit",
        name: "limit",
        component: () => import("../views/Limit.vue"),
      },
      {
        path: "order",
        name: "order",
        component: () => import("../views/Order.vue"),
      },
      {
        path: "system",
        name: "system",
        component: () => import("../views/System.vue"),
      },
      {
        path: "detail",
        name: "detail",
        component: () => import("../views/Detail.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

export default router;
